const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
module.exports = {
  entry: {
    "app.bundle": "./src/app.js",
    "contact": "./src/contact.js",
  },
  output:{
    path: path.resolve(__dirname+'/dist'),
    filename:"[name].[chunkhash].js"
  },
  plugins:[
    new HtmlWebpackPlugin({
      // title:'hello world',
      template:'./src/index.html',
      filename:'index.html',
      hash:true,
      minify:{
        collapseWhitespace: true,
      },
      excludeChunks:['contact']
    }),
    new HtmlWebpackPlugin({
      title:'hello world',
      template:'./src/contact.html',
      filename:'contact.html',
      hash:true,
      minify:{
        collapseWhitespace: true,
      },
      chunks:['contact']
    }),
    new ExtractTextPlugin({
      filename: 'style.css',
      disable: false,
      publicPath: 'css/'
    }),
    new CleanWebpackPlugin(['dist']),
    new webpack.NamedModulesPlugin(),
    // new webpack.HotModuleReplacementPlugin(),
    new webpack.ProvidePlugin({
      $: 'jquery',
      jQuery: 'jquery'
    }),
  ],
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader?sourceMap', 'sass-loader?sourceMap']
        })
      },
      // { 
      //   test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ 
      // },
      {
        test: /\.(gif|png|jpe?g|svg)$/i,
        use: [{
          loader:'file-loader',
          options: {
            name: '[name].[ext]',
            outputPath: 'images/'
          }
        },
          {
            loader: 'image-webpack-loader',
            options: {
              bypassOnDebug: true
            }
          }
        ]
      },
      {
        test: /\.html$/,
        use: [{
          loader: 'html-loader',
          options: {
            // minimize: true
          }
        }]
      }
    ]
  },
}